<template>
  <pf-table
    ref="pfTable"
    v-model="form"
    :columns="columns"
    :form-items="formItems"
    @get-table-data="getTableData"
  />
</template>

<script>
import { getUsedList } from '@/api/coupon'
export default {
  name: 'UsedList',
  data() {
    return {
      form: {},
      loading: false
    }
  },
  computed: {
    columns() {
      const attrs = { 'min-width': '150px' }
      return [
        { label: '优惠券ID', prop: 'couponId', attrs },
        { label: '用户名称', prop: 'userName', attrs },
        { label: '手机号', prop: 'userMobile', attrs },
        { label: '领券时间', prop: 'getCouponDate', attrs },
        { label: '使用时间', prop: 'useCouponDate', attrs },
        { label: '订单编号', prop: 'orderId', attrs }
      ]
    },
    formItems() {
      return [
        {
          type: 'input',
          label: '用户名称',
          prop: 'userName'
        }, {
          type: 'input',
          label: '手机号',
          prop: 'mobile'
        }
      ]
    }
  },

  methods: {

    getTableData({ pageNo, pageSize, ...formQuery }, done) {
      this.loading = true
      const data = {
        pageNo,
        pageSize,
        ...formQuery
      }
      getUsedList(data).then(res => {
        this.loading = false
        done({ data: res.data || [], total: res.count || 0 })
      }).catch(() => {
        done({ data: [], total: 0 })
        this.loading = false
      })
    }
  }
}
</script>

<style lang="scss" scoped></style>
